import { router } from '@/router';
import { LINK_ENTERPRISE_OVERVIEW } from '../router/routes/business/enterprise';
import { LINK_ZLIBHTML_OVERVIEW, LINK_PDFVIEW_OVERVIEW, LINK_IMAGE_OVERVIEW, LINK_LAWS_OVERVIEW, LINK_WPS_OVERVIEW } from '../router/routes/business/other';
import { encryptByBase64 } from '@vc/utils';
import { LINK_GREEN_BOND_DETAIL, LINK_GREEN_PROJECT_DETAIL } from '@/router/routes/business/greenFinance/greenBond';

/** 跳转 f9 */
export function toF9(id) {
  const { go } = useRouterHelper(router);
  if (!id) {
    return;
  }
  return go(LINK_ENTERPRISE_OVERVIEW + '/' + encodeURIComponent(id));
}

/**
 * @function 根据后缀类型跳转页面地址
 * @param {String} fileType 附件类型 必传
 * @param {String} url 附件地址
 * @param {String} id 正文id
 * @param {String} bizType 正文类型
 // * @param {String} page pdf指定页数
 * @param {String} position 图片预览定位信息
 */
export function setHrefUrlTool(fileType, url = '', id = '', bizType = '', position = '') {
  const { go } = useRouterHelper(router);
  if (['html', 'zip'].indexOf(fileType) !== -1 || (!fileType && id)) {
    if (id) {
      return go(LINK_ZLIBHTML_OVERVIEW + '/' + encryptByBase64(url) + '/' + encryptByBase64(id) + (bizType ? '/' + encryptByBase64(bizType) : ''));
    } else {
      return go(LINK_ZLIBHTML_OVERVIEW + '/' + encryptByBase64(url));
    }
  } else if (['pdf'].indexOf(fileType) !== -1) {
    return go(LINK_PDFVIEW_OVERVIEW + '/' + encryptByBase64(url));
  } else if (['excel', 'word'].indexOf(fileType) !== -1) {
    // excel,word用微软自带浏览页面预览
    return go(LINK_PDFVIEW_OVERVIEW + '/' + encryptByBase64('https://view.officeapps.live.com/op/view.aspx?src=' + url));
  } else if (['other'].indexOf(fileType) !== -1) {
    // 图片预览定位
    if (url && url.slice(url.length - 4, url.length) === '.wps') {
      return go(LINK_WPS_OVERVIEW + '/' + encryptByBase64(url));
    } else {
      if (position) {
        return go(LINK_IMAGE_OVERVIEW + '/' + encryptByBase64(url) + '/' + encryptByBase64(JSON.stringify(position)));
      } else {
        return go(LINK_IMAGE_OVERVIEW + '/' + encryptByBase64(url));
      }
    }
  } else {
    window.open(url);
  }
}

/** 跳转绿色债券详情 */
export function toBondDetail(id) {
  const { go } = useRouterHelper(router);
  if (!id) {
    return;
  }
  return go(LINK_GREEN_BOND_DETAIL + '/' + encodeURIComponent(id));
}

/** 跳转绿色项目详情 */
export function toProjectDetail(id) {
  const { go } = useRouterHelper(router);
  if (!id) {
    return;
  }
  return go(LINK_GREEN_PROJECT_DETAIL + '/' + encodeURIComponent(id));
}

/** 跳转法规详情 */
export function toLawDetail(item) {
  const { go } = useRouterHelper(router);
  if (!item) {
    return;
  }
  return go(LINK_LAWS_OVERVIEW + '/' + encryptByBase64(item));
}
